/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.wxrobot.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.wxrobot.entity.Customer;
import com.jeesite.modules.wxrobot.service.CustomerService;

/**
 * 活动客户信息Controller
 * @author laozhang
 * @version 2018-07-31
 */
@Controller
@RequestMapping(value = "${adminPath}/wxrobot/customer")
public class CustomerController extends BaseController {

	@Autowired
	private CustomerService customerService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Customer get(String id, boolean isNewRecord) {
		return customerService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("wxrobot:customer:view")
	@RequestMapping(value = {"list", ""})
	public String list(Customer customer, Model model,HttpServletRequest request) {
		model.addAttribute("customer", customer);
		/*String ss = request.getServletContext().getRealPath("/");
		customerService.generateExclusivePoster("a40b125808094f9787a45acf2e93d125","10000",ss);*/
		return "modules/wxrobot/customerList";
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("wxrobot:customer:view")
	@RequestMapping(value = {"activityCustomerList", ""})
	public String activityCustomerList(Customer customer, Model model,HttpServletRequest request) {
		model.addAttribute("customer", customer);
		return "modules/wxrobot/activityCustomerList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("wxrobot:customer:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<Customer> listData(Customer customer, HttpServletRequest request, HttpServletResponse response) {
		Page<Customer> page = customerService.findPage(new Page<Customer>(request, response), customer);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("wxrobot:customer:view")
	@RequestMapping(value = "form")
	public String form(Customer customer, Model model) {
		model.addAttribute("customer", customer);
		return "modules/wxrobot/customerForm";
	}

	/**
	 * 保存活动客户信息
	 */
	@RequiresPermissions("wxrobot:customer:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Customer customer) {
		customerService.save(customer);
		return renderResult(Global.TRUE, text("保存活动客户信息成功！"));
	}

	/**
	 * 保存活动客户信息
	 */
	@RequiresPermissions("wxrobot:customer:edit")
	@PostMapping(value = "getDiscount")
	@ResponseBody
	public String getDiscount(@Validated Customer customer) {
		customer.setStatus("1");
		customerService.updateDiscountStatus(customer);
		return renderResult(Global.TRUE, text("领取优惠成功！"));
	}
	
}